<div id="sf_admin_container" class="container-fluid well">
    <div id="sf_admin_content" class="row-fluid">
        <div class="span12">
            <h3>Inscripción a Exámenes Finales</h3>
            <?php
            date_default_timezone_set('America/Argentina/Cordoba');
            $count_examenes = 0;
            ?>
            <form method="post" action="<?php echo url_for('inscripciones/inscribirFinales') ?>">
                <div class="sf_admin_form">
                    <?php foreach ($modulos_alumno as $key => $modulos_cuatrimestre): ?>
                        <?php
                        $show = false;
                        $timediff = 0;
                        if(date('w') == 5 || date('w') == 6) {
                            $timediff = 244800;
                        } else {
                            $timediff = 158400;
                        }
                        ?>
                        <?php foreach ($modulos_cuatrimestre as $modulo): ?>
                            <?php
                            $timestamp = date('Y-m-d H:i:s', strtotime((date('Y-m-d', strtotime($modulo['fecha'])) . ' ' . date('H:i:s', strtotime($modulo['hora'])))));
                            if ((int) $modulo['examen_id'] && (strtotime($timestamp) - time()) > $timediff) {
                                $show = true;
                                $count_examenes++;
                            }
                            ?>
                        <?php endforeach ?>
                        <?php if ($show): ?>
                            <table class="table table-bordered table-condensed table-striped">
                                <tbody>
                                    <tr class="warning">
                                        <td colspan="4"><?php echo $key ?>° Cuatrimestre</td>
                                    </tr>
                                    <tr class="warning">
                                        <td style="width: 40%;">Unidad Curricular</td>
                                        <td style="width: 20%;">Fecha</td>
                                        <td style="width: 20%;">Docente</td>
                                        <td style="width: 20%;">Condición</td>
                                    </tr>
                                    <?php foreach ($modulos_cuatrimestre as $modulo): ?>
                                        <?php $inscripto_examen = (int) $modulo['condicion_examen']; ?>
                                        <?php
                                        $timestamp = date('Y-m-d H:i:s', strtotime((date('Y-m-d', strtotime($modulo['fecha'])) . ' ' . date('H:i:s', strtotime($modulo['hora'])))));
                                        if ((int) $modulo['examen_id'] && (strtotime($timestamp) - time()) > $timediff): ?>
                                            <tr <?php echo $inscripto_examen ? 'class="success"' : '' ?>>
                                                <td><?php echo $modulo['modulo'] . ($modulo['regimen'] == 'Anual' ? ' (Anual)' : '') ?></td>
                                                <td><?php echo date('d/m/Y', strtotime($modulo['fecha'])) . ' ' . date('H:i', strtotime($modulo['hora'])) ?> hs</td>
                                                <td><?php echo $modulo['apellido'] . ', ' . $modulo['nombre'] ?></td>
                                                <td>
                                                    <select class="condensed" name="examen[<?php echo $modulo['examen_id'] ?>][condicion]" id="examen_<?php echo $modulo['examen_id'] ?>_condicion">
                                                        <?php
                                                        foreach ($condiciones as $value => $condicion) {
                                                            echo '<option ' . ($inscripto_examen && $inscripto_examen == $value ? 'selected' : '') . ' value="' . $value . '">' . $condicion . '</option>';
                                                        }
                                                        ?>
                                                    </select>
                                                </td>
                                            </tr>
                                        <?php endif ?>
                                    <?php endforeach ?>
                                </tbody>
                            </table>
                        <?php endif ?>
                    <?php endforeach ?>
                    <?php if($count_examenes == 0): ?>
                    <h4>No hay exámenes disponibles</h4>
                    <?php endif ?>
                    <input type="submit" class="btn btn-large btn-warning pull-right" value="Guardar" />
                    <div class="clearfix"></div>
                </div>
            </form>
        </div>
    </div>
</div>